package com.orkasgb.framework.hadoop.mapperreduce.combiner;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
import java.util.StringTokenizer;

public class WordCountMapper extends Mapper<LongWritable, Text, Text, LongWritable> {
    final Text k = new Text();
    final LongWritable v = new LongWritable(1);

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        // 数据实例：xiaxiao
        String line = value.toString();
        final StringTokenizer tokenizer = new StringTokenizer(line);
        while (tokenizer.hasMoreTokens()) {
            final String token = tokenizer.nextToken();
            k.set(token);
            context.write(k, v);
        }
    }
}
